package com.kotiln.lgc.lib_base.adapter

import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import androidx.viewpager.widget.ViewPager

/**
 *@fileName BasePagerAdapter
 *@date2021/1/27  13:00
 *@author BasePagerAdapter$
 *@describe TODO
 *@desc ViewPager 适配器
 */
class BasePagerAdapter(private val mList:MutableList<View>):PagerAdapter() {
    override fun getCount(): Int {
        return mList.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        //将View添加到ViewGroup中
        (container as ViewPager).addView(mList[position])
        //返回当前View
        return mList[position]
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
//        super.destroyItem(container, position, `object`)
        (container as ViewPager).removeView(mList[position])
    }
}